<?php

require_once "var.lib.php";

function UploadImageProduk($in_produk_gambar_name) {
    //direktori gambar
    $vdir_upload = VAR_URL_GAMBAR_PRODUK;
    $vfile_upload = $vdir_upload . $in_produk_gambar_name;

    //Simpan gambar dalam ukuran sebenarnya
    move_uploaded_file($_FILES["in_produk_gambar"]["tmp_name"], $vfile_upload);

    //identitas file asli
    $im_src = imagecreatefromjpeg($vfile_upload);
    $src_width = imageSX($im_src);
    $src_height = imageSY($im_src);

    //Simpan dalam versi small 110 pixel
    //Set ukuran gambar hasil perubahan
    $dst_width = 85;
    $dst_height = ($dst_width / $src_width) * $src_height;

    //proses perubahan ukuran
    $im = imagecreatetruecolor($dst_width, $dst_height);
    imagecopyresampled($im, $im_src, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);

    //Simpan gambar
    imagejpeg($im, $vdir_upload . "small_" . $in_produk_gambar_name);

    //Hapus gambar di memori komputer
    imagedestroy($im_src);
    imagedestroy($im);
}

function UploadImageGaleri($in_galeri_gambar_name) {
    //direktori gambar
    $vdir_upload = VAR_URL_GAMBAR_GALERI;
    $vfile_upload = $vdir_upload . $in_galeri_gambar_name;

    //Simpan gambar dalam ukuran sebenarnya
    move_uploaded_file($_FILES["in_galeri_gambar"]["tmp_name"], $vfile_upload);

    //identitas file asli
    $im_src = imagecreatefromjpeg($vfile_upload);
    $src_width = imageSX($im_src);
    $src_height = imageSY($im_src);

    //Simpan dalam versi small 110 pixel
    //Set ukuran gambar hasil perubahan
    $dst_width = 85;
    $dst_height = ($dst_width / $src_width) * $src_height;

    //proses perubahan ukuran
    $im = imagecreatetruecolor($dst_width, $dst_height);
    imagecopyresampled($im, $im_src, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);

    //Simpan gambar
    imagejpeg($im, $vdir_upload . "small_" . $in_galeri_gambar_name);

    //Hapus gambar di memori komputer
    imagedestroy($im_src);
    imagedestroy($im);
}

function UploadBanner($in_produk_gambar_name) {
    //direktori banner
    $vdir_upload = var_url_banner;
    $vfile_upload = $vdir_upload . $in_produk_gambar_name;

    //Simpan gambar dalam ukuran sebenarnya
    move_uploaded_file($_FILES["in_produk_gambar"]["tmp_name"], $vfile_upload);
}

function UploadFile($in_produk_gambar_name) {
    //direktori file
    $vdir_upload = var_url_files;
    $vfile_upload = $vdir_upload . $in_produk_gambar_name;

    //Simpan gambar dalam ukuran sebenarnya
    move_uploaded_file($_FILES["in_produk_gambar"]["tmp_name"], $vfile_upload);
}

?>
